﻿

//初始化
if (typeof ($) != "undefined") {
    var fun = getPar1("fun");
    $(document).ready(function () {
        $("#txtYear").change(function () {
            $("#YearMonth").val($("#txtYear").val() + "-" + $("#txtMonth").val());
        });
        $("#txtMonth").change(function () {
            $("#YearMonth").val($("#txtYear").val() + "-" + $("#txtMonth").val());
        });
    });

    $("#YearMonth").val(instance[0].YearMonth);
    if ($("#YearMonth").val() == "") {
        $("#YearMonth").val($("#txtYear").val() + "-" + $("#txtMonth").val());
    }

    if (fun == "view" || fun == "edit") {
        GetEmpNameByEmpID(instance[0].EmployeeID);
        GetEmpcodeByEmpID(instance[0].EmployeeID);
        //debugger;
        var yearMonth = $("#YearMonth").val();
        $("#txtYear").val(yearMonth.split("-")[0]);
        $("#txtMonth").val(yearMonth.split("-")[1]);
    }

    //debugger;
    if (fun == "view") {
        parent.document.getElementById("yui-gen7-button").style.display = "none";
        $("div input").attr("disabled", true).css("background", "whitesmoke");
        $("div select").attr("disabled", true).css("background", "whitesmoke");
        $("div button").hide();
    }
}


//选择员工
var employeeId;
var ValueChanged = function () {
    employeeId = $("#empId").val();
}

var TextChanged = function () {
    var employeeName = $("#txtempId").val();
    if (employeeId == "" || employeeId == "undefined") {
        return;
    }
    if (employeeName == "" || employeeName == "undefined") {
        return;
    }
    //debugger
    $("input[name='txtEmployeeID']").last().val(employeeName);
    $("input[name='EmployeeID']").last().val(employeeId);
    GetEmpcodeByEmpID(employeeId);
}

//获取员工编号
function GetEmpcodeByEmpID(empId) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");

        for (var o in list.rows) {
            var t = list.rows[o].EmployeeCode;
            if (typeof (t) != "undefined") {
                $("input[name='EmployeeCode']").last().val(t);
            }
        }

    });
}

//获取员工姓名
function GetEmpNameByEmpID(empId) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");

        for (var o in list.rows) {
            var t = list.rows[o].CName;
            if (typeof (t) != "undefined") {
                $("input[name='txtEmployeeID']").last().val(t);
            }
        }

    });
}

var fnCheckData = function () {
    try {
        if ($("#txtEmployeeID").val() == "") {
            return "员工姓名不能为空！";
        }
        if ($("#EmployeeCode").val() == "") {
            return "员工编号不能为空！";
        }
        if ($("#AccountReceivable").val() == "") {
            $("#AccountReceivable").focus();
            return "应收金额不能为空！";
        }
        if ($("#AccountReceivable").val().length > 8) {
            $("#AccountReceivable").focus();
            return "应收金额最多输入8位数字！";
        }
        if ($("#Laborage").val() == "") {
            $("#Laborage").focus();
            return "工资不能为空！";
        }
        if ($("#Laborage").val().length > 8) {
            $("#Laborage").focus();
            return "工资最多输入8位数字！";
        }
        if ($("#EmpEndowment").val() == "") {
            $("#EmpEndowment").focus();
            return "养老个人交不能为空！";
        }
        if ($("#EmpEndowment").val().length > 8) {
            $("#EmpEndowment").focus();
            return "养老个人交最多输入8位数字！";
        }
        if ($("#CoEndowment").val() == "") {
            $("#CoEndowment").focus();
            return "养老公司交不能为空！";
        }
        if ($("#CoEndowment").val().length > 8) {
            $("#CoEndowment").focus();
            return "养老公司交最多输入8位数字！";
        }
        if ($("#EmpHousing").val() == "") {
            $("#EmpHousing").focus();
            return "住房个人交不能为空！";
        }
        if ($("#EmpHousing").val().length > 8) {
            $("#EmpHousing").focus();
            return "住房个人交最多输入8位数字！";
        }
        if ($("#CoHousing").val() == "") {
            $("#CoHousing").focus();
            return "住房公司交不能为空！";
        }
        if ($("#CoHousing").val().length > 8) {
            $("#CoHousing").focus();
            return "住房公司交最多输入8位数字！";
        }
        if ($("#EmpHospitalization").val() == "") {
            $("#EmpHospitalization").focus();
            return "医疗个人交不能为空！";
        }
        if ($("#EmpHospitalization").val().length > 8) {
            $("#EmpHospitalization").focus();
            return "医疗个人交最多输入8位数字！";
        }
        if ($("#CoHospitalization").val() == "") {
            $("#CoHospitalization").focus();
            return "医疗公司交不能为空！";
        }
        if ($("#CoHospitalization").val().length > 8) {
            $("#CoHospitalization").focus();
            return "医疗公司交最多输入8位数字！";
        }
        if ($("#EmpCompo").val() == "") {
            $("#EmpCompo").focus();
            return "工伤个人交不能为空！";
        }
        if ($("#EmpCompo").val().length > 8) {
            $("#EmpCompo").focus();
            return "工伤个人交最多输入8位数字！";
        }
        if ($("#CoCompo").val() == "") {
            $("#CoCompo").focus();
            return "工伤公司交不能为空！";
        }
        if ($("#CoCompo").val().length > 8) {
            $("#CoCompo").focus();
            return "工伤公司交最多输入8位数字！";
        }
        if ($("#EmpUnemployment").val() == "") {
            $("#EmpUnemployment").focus();
            return "失业个人交不能为空！";
        }
        if ($("#EmpUnemployment").val().length > 8) {
            $("#EmpUnemployment").focus();
            return "失业个人交最多输入8位数字！";
        }
        if ($("#CoUnemployment").val() == "") {
            $("#CoUnemployment").focus();
            return "失业公司交不能为空！";
        }
        if ($("#CoUnemployment").val().length > 8) {
            $("#CoUnemployment").focus();
            return "失业公司交最多输入8位数字！";
        }
        if ($("#EmpProcreate").val() == "") {
            $("#EmpProcreate").focus();
            return "生育个人交不能为空！";
        }
        if ($("#EmpProcreate").val().length > 8) {
            $("#EmpProcreate").focus();
            return "生育个人交最多输入8位数字！";
        }
        if ($("#CoProcreate").val() == "") {
            $("#CoProcreate").focus();
            return "生育公司交不能为空！";
        }
        if ($("#CoProcreate").val().length > 8) {
            $("#CoProcreate").focus();
            return "生育公司交最多输入8位数字！";
        }

        var reg = /^\d+(\.\d+)?$/;
        if (reg.test($("#AccountReceivable").val()) == false) {
            $("#AccountReceivable").focus();
            return "应收金额需要输入非负数字!";
        }
        if (reg.test($("#Laborage").val()) == false) {
            $("#Laborage").focus();
            return "工资需要输入非负数字!";
        }
        if (reg.test($("#EmpEndowment").val()) == false) {
            $("#EmpEndowment").focus();
            return "养老个人交需要输入非负数字!";
        }
        if (reg.test($("#CoEndowment").val()) == false) {
            $("#CoEndowment").focus();
            return "养老公司交需要输入非负数字!";
        }
        if (reg.test($("#EmpHousing").val()) == false) {
            $("#EmpHousing").focus();
            return "住房个人交需要输入非负数字!";
        }
        if (reg.test($("#CoHousing").val()) == false) {
            $("#CoHousing").focus();
            return "住房公司交需要输入非负数字!";
        }
        if (reg.test($("#EmpHospitalization").val()) == false) {
            $("#EmpHospitalization").focus();
            return "医疗个人交需要输入非负数字!";
        }
        if (reg.test($("#CoHospitalization").val()) == false) {
            $("#CoHospitalization").focus();
            return "医疗公司交需要输入非负数字!";
        }
        if (reg.test($("#EmpCompo").val()) == false) {
            $("#EmpCompo").focus();
            return "工伤个人交需要输入非负数字!";
        }
        if (reg.test($("#CoCompo").val()) == false) {
            $("#CoCompo").focus();
            return "工伤公司交需要输入非负数字!";
        }
        if (reg.test($("#EmpUnemployment").val()) == false) {
            $("#EmpUnemployment").focus();
            return "失业个人交需要输入非负数字!";
        }
        if (reg.test($("#CoUnemployment").val()) == false) {
            $("#CoUnemployment").focus();
            return "失业公司交需要输入非负数字!";
        }
        if (reg.test($("#EmpProcreate").val()) == false) {
            $("#EmpProcreate").focus();
            return "生育个人交需要输入非负数字!";
        }
        if (reg.test($("#CoProcreate").val()) == false) {
            $("#CoProcreate").focus();
            return "生育公司交需要输入非负数字!";
        }
    }
    catch (e)
     { }
}

